package com.work.leecode.other.middle;

/**
 * 整数反转
 */
public class Lc7 {
    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int tmp = x % 10;

            //int最大值判断
            if (res > 214748364 || (res == 214748364 && tmp > 7)) {
                return 0;
            }

            //int最小值判断
            if (res < -214748364 || (res == -214748364 && tmp < -8)) {
                return 0;
            }

            res = res * 10 + tmp;
            x /= 10;
        }
        return res;
    }
}
